package com.dht.xiao.jianye.command.base.serialport.log;


import com.dht.xiao.jianye.command.base.util.BaseLog;
import com.dht.xiao.jianye.command.base.util.CommonUtil;
import com.dht.xiao.jianye.utils.DateUtil;
import com.licheedev.myutils.LogPlus;

/**
 * @author :      fangbingran
 * @aescription : todo(这里用一句话描述这个类的作用)
 * @date :        2019/06/13  20:13
 */
public class SerialPortLoggerFactory {
    private static SerialPortLogger mSerialPortLogger;
    private static final String SERIAL_PORT_LOG_TAG = "SerialPortLogTag";

    public SerialPortLoggerFactory() {
    }

    public static void createLogger(SerialPortLogger serialPortLogger) {
        mSerialPortLogger = serialPortLogger;
    }

    public static void debug(String logger) {
        if (mSerialPortLogger != null) {
            mSerialPortLogger.debug(logger);
        } else {
            BaseLog.print(logger);
        }

    }

    public static void info(String logger,Boolean isLog) {
        if(isLog) {
            if (mSerialPortLogger != null) {
                mSerialPortLogger.info(logger);
            } else {
                LogPlus.e(SERIAL_PORT_LOG_TAG," 时间="+ DateUtil.getTodayDateTime()+ logger);
                //  BaseLog.print(logger);
            }
        }else {
            LogPlus.d(SERIAL_PORT_LOG_TAG, " 时间="+ DateUtil.getTodayDateTime()+ logger);
        }

    }

    public static void warn(String logger) {
        if (mSerialPortLogger != null) {
            mSerialPortLogger.warn(logger);
        } else {
            BaseLog.print(logger);
        }

    }

    public static void warn(String logger, Throwable throwable) {
        if (mSerialPortLogger != null) {
            mSerialPortLogger.warn(logger, CommonUtil.getThrowableStrRep(throwable), throwable);
        } else {
            BaseLog.print(logger);
        }

    }

    public static void error(String logger) {
        if (mSerialPortLogger != null) {
            mSerialPortLogger.error(logger);
        } else {
            BaseLog.print(logger);
        }

    }

    public static void error(String logger, Throwable throwable) {
        if (mSerialPortLogger != null) {
            mSerialPortLogger.error(logger, CommonUtil.getThrowableStrRep(throwable), throwable);
        } else {
            BaseLog.print(logger);
        }

    }
}
